<template>
  <ul>
    <li v-for="(item, index) in data" :key="index" @click.stop="toggleSubList(item)">
      {{item.text}}
     <Tree :data="item.children" 
      v-if="item.children && item.children.length && item.isExpend"/>
    </li>
  </ul>
</template>

<script> 
/* 一个组件内部有自己的组件标签 */
export default {  // 
  name: 'Tree', // 作为内部的标签名
  props: ['data'],

  methods: {
    toggleSubList (item) {
      if (item.hasOwnProperty('isExpend')) {
        item.isExpend = !item.isExpend
      } else {
        this.$set(item, 'isExpend', true)
      }
    }
  }
}
</script>